package com.ht.impl.myactions;

import com.ht.aems.swing.util.MyAction;
import com.ht.impl.ResourceTypeCons;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxGraph;
import com.mxgraph.swing.mxGraphComponent;

import java.awt.event.ActionEvent;

import org.w3c.dom.Document;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Wang jiaxiang
 *         Date: 2010-7-7
 */
public class AddShadow extends MyAction implements ResourceTypeCons {
    Document doc = mxUtils.createDocument();
    public void actionPerformed(ActionEvent e) {
        mxGraphComponent component = (mxGraphComponent) e.getSource();
        Object[] objs = component.getGraph().getSelectionCells();
        if (objs.length == 0)
            return;
        mxGraph graph = component.getGraph();
        mxIGraphModel model = graph.getModel();
        mxCell cell;
        model.beginUpdate();
        String originalStyle;
        for(Object obj : objs) {
            cell = (mxCell) obj;
            originalStyle = cell.getStyle();
            if(originalStyle == null)
                originalStyle = "";
            model.setStyle(cell, originalStyle + (originalStyle.contains(";") ? ";shadow=true" : "shadow=true"));
        }
        model.endUpdate();
        component.refresh();
    }
}